<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/include/head.jsp"%>
<div id="cc" class="easyui-layout" style="width:100%;height:100%;">   
	<div data-options="region:'center',title:'进货单-${vo.orderCode}信息'" style="padding:5px;background:#eee;">
		<form id="editForm"   method="post" enctype="multipart/form-data" >
			<input name="id" type="hidden" value="${vo.id}">
			<table cellpadding="0" cellspacing="1" class="formtable">
				<tr>
				<td align="right"><label class="Validform_label">订单编号:</label></td>
				<td class="value">
				<input class="easyui-textbox" type="text"  id="orderCode" name="orderCode"
				 data-options="required:true" value="${vo.orderCode}" />
				</td>
				<td align="right"><label class="Validform_label">产品名称:</label></td>
				<td class="value">
				<input type="hidden"  id="productId" name="productId" value="${vo.productId}" />
				<input   type="text"  id="productName" name="productName"
				  value="${vo.productName}" />
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">客户名称:</label></td>
				<td class="value">
				<input  type="hidden"  id="cusId" name="cusId"  value="${vo.cusId}" />
				<input class="easyui-textbox" type="text"  id="cusName" name="cusName"
				 data-options="required:true" value="${vo.cusName}" />
				</td>
				<td align="right"><label class="Validform_label">订单日期:</label></td>
				<td class="value">
				<input class="easyui-datebox" type="text"  id="orderTime" name="orderTime"
				 data-options="required:true" value="${vo.orderTime}" />
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">数量:</label></td>
				<td class="value">
				<input class="easyui-numberbox" type="text"  id="productNum" name="productNum"
				 data-options="required:true" value="${vo.productNum}" />
				</td>
				<td align="right"><label class="Validform_label">单价:</label></td>
				<td class="value">
				<input class="easyui-numberbox" type="text"  id="unitPrice" name="unitPrice"
				 data-options="required:true,min:0,precision:2" value="${vo.unitPrice}" />
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">总价:</label></td>
				<td class="value">
				<input class="easyui-numberbox" type="text"  id="totalPrice" name="totalPrice"
				 data-options="required:true,min:0,precision:2,readonly:true" value="${vo.totalPrice}" />
				</td>
				<td align="right"><label class="Validform_label">单位:</label></td>
				<td class="value">
				<input class="easyui-textbox" type="text"  id="unit" name="unit"
				 data-options="required:true" value="${vo.unit}" />
				</td>
				</tr>
				
				<tr>
				<td align="right"><label class="Validform_label">运费:</label></td>
				<td class="value">
				<input class="easyui-numberbox" type="text"  id="freight" name="freight"
				 data-options="required:true,min:0,precision:2" value="${vo.freight}" />
				</td>
				<td align="right"><label class="Validform_label">调整金额:</label></td>
				<td class="value">
				<input class="easyui-numberbox" type="text"  id="discountPrice" name="discountPrice"
				 data-options="required:true,precision:2" value="${vo.discountPrice}" />
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">实付金额:</label></td>
				<td class="value">
				<input class="easyui-numberbox" type="text"  id="finnalPrice" name="finnalPrice"
				 data-options="required:true,min:0,precision:2,readonly:true" value="${vo.finnalPrice}" />
				</td>
				</tr>
				<textarea   id="remark" name="remark" style="display: none">${vo.remark}</textarea>
				<input  type="hidden"  id="depot" name="depot"  value="${vo.depot}" />
				<input  type="hidden" id="status" name="status"  value="${vo.status}" />
				<input  type="hidden"  id="recvDate" name="recvDate"  value="${vo.recvDate}" />
				 
			</table>
		</form>
	</div>
	<div data-options="region:'south'" style="height:35px;text-align: center;padding-top: 5px">
	 	<a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="save()" >保存</a>  
	 	<a id="btncancel" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="closeDialog()">关闭</a>  
	 </div>
</div>   
<script type="text/javascript">
var dialog = frameElement.dialog;
$(function() {
	
	$('#productNum').numberbox({    
	    onChange:function(newValue,oldValue){
	    	changeUnit();
	    }
	});
	
	
	$('#unitPrice').numberbox({    
	    onChange:function(newValue,oldValue){
	    	changeUnit();
	    }
	});
	
	
	$('#totalPrice').numberbox({    
	    onChange:function(newValue,oldValue){
	    	changeTotal();
	    }
	});
	
	$('#freight').numberbox({    
	    onChange:function(newValue,oldValue){
	    	changeTotal();
	    }
	});
	$('#discountPrice').numberbox({    
	    onChange:function(newValue,oldValue){
	    	changeTotal();
	    }
	});
	$('#productName').textbox({    
	    buttonText:'Search',    
	    onClickButton:function(){selectProduct();}
	});
	$('#cusName').textbox({    
	    buttonText:'Search',    
	    onClickButton:function(){selectCus();}
	});
	$('#editForm').form({    
	    url:'saveOrUpdate.do',    
	    iframe:false,
	    onSubmit: function(){ 
	    	//do your things on submint
	    },    
	    success:function(data){    
	    	data = JSON.parse(data);
	    	if(data.result == '1')
	    	{
	    		$.messager.alert("保存结果","保存成功",'info',function(){
	    			if($.isFunction(dialog.dialog('options').callback))
	    			{
	    				dialog.dialog('options').callback(data);
	    			}
	    			closeDialog();
		    	});	
	    	}
	    	else
	    	{
	    		$.messager.alert("保存结果","保存失败：" + data.message,'error',function(){
	    			
		    	});
	    	}
	    }    
	});  
});

function changeUnit()
{
	$('#totalPrice').numberbox('setValue',$('#productNum').numberbox('getValue')*$('#unitPrice').numberbox('getValue'))	;
}

function changeTotal()
{
	var total = 0.0;
	
	if($('#totalPrice').numberbox('getValue'))
	{
		total += parseFloat($('#totalPrice').numberbox('getValue'));
	}
	
	if($('#freight').numberbox('getValue'))
	{
		total += parseFloat($('#freight').numberbox('getValue'));
	}
	if($('#discountPrice').numberbox('getValue'))
	{
		total += parseFloat($('#discountPrice').numberbox('getValue'));
	}
	$('#finnalPrice').numberbox('setValue',total);
}
function selectProduct()
{
	ProductDialog('productId','productName',false,function(data){
		var selRow = data.data;
		$("#unitPrice").numberbox('setValue',selRow.pprice);
		$("#unit").textbox('setValue',selRow.unit);
	})	;

}
function selectCus()
{
	CustomerDialog('cusId','cusName',false,function(data){
		var selRow = data.data[0];
	})	;

}
function save(){
	if(!$("#editForm").form('validate'))
	{
		$.messager.alert("验证结果","表单验证失败",'error',function(){
    	});
		return;
	}
	$("#editForm").submit();  
}
function closeDialog()
{
	dialog.dialog("close");
}

</script>
<%@include file="/include/foot.jsp"%>